#################################################
#												#
# Provide Coefficient Plots for Global Sample   #
#                   			                #
#################################################


rm(list=ls()) 

library(foreign)
library(arm)
library(splines)

# create a vector to store the variable names
  
  var.names <- c("Systemic Instability","","","Regional Systemic Instability","","","", "% GP Civil Wars","","","GP Inflationary Crises","","","", "Regional GP Wars","","", "% GP Wars","","","","GP War Termination","","","Regional GP War Termination","","","", "Number of New Dyads", "","","Number of Secessions","","","","Number of Proxy Wars","","","GP Alliance Shifts","","","","Composite Instability Measure","","","Regional Composite Instability")
var.names<-rev(var.names)





# set the graphical parameters
par(
  family = "serif",  
  oma = c(0,0,0,0),  # Since it is a single plot, I set the outer margins to zero.
  mar = c(5,10,4,2) 
  )

# create an empty plot for total customization
plot(NULL,                              # create empty plot
  xlim = c(0, 0.04),                      # set xlim by guessing
  ylim = c(.7, length(var.names) + .3), # set ylim by the number of variables
  axes = F, xlab = NA, ylab = NA)       # turn off axes and labels

# add the data
estL <- c(.0042849,"","",.0045288,"","","",.0040767,"","",.0037634,"","","",.0040449,"","", .0043449,"","","",.0052367,"","",.004887,"","","",.0042345,"","",.0049898 ,"","","", .00507,"","",.0049025, "","","",.0054804,"","",.0045427) 
estH <- c(.022615,"","", .0218667,"","","",.0109495 ,"","",.0186822 ,"","","",.019493,"","",.0124613 ,"","","",.0055187,"","", .0111536,"","","", .014817,"","",.0164442,"","","",.0241635,"","",.017333, "","","",.0249717,"","",.0168127) 


estL<-rev(estL)
estH <-rev(estH)


# conveniently store the estimates (minus the constant)
est_lL <- c(.003723,"","",.0038347,"","","",.0033806 ,"","",.0031239,"","","",.0034446,"","",.0037149,"","","", .0049307,"","",.0045825,"","","",.0037642,"","",.0048151,"","","",.0049575 ,"","",.004554, "","","",.0050345,"","",.0041809)
est_lH <- c(.0048468,"","",.0052228,"","","",.0047727,"","",.0044029,"","","",.0046452,"","",.0049749,"","","",.0055427,"","",.0051916,"","","",.0047049,"","",.0051644,"","","",.0051825,"","",.005251, "","","",.0059262,"","",.0049045)

est_lL <-rev(est_lL)

est_lH <-rev(est_lH)

est_hL <- c(.0155198 ,"","",.0116334,"","","",.0076993,"","",.0130674,"","","",.0126391,"","",.0076743,"","","",.0041712, "","",.0067086,"","","", .0105665,"","",.0099316,"","","",.0144618,"","",.0117274, "","","",.0182918,"","",.0101224)
est_hH <- c(.0297101,"","",.0321,"","","",.0141998,"","",.0242969,"","","",.0263468,"","",.0172484,"","", "",.0068663,"","",.0155985,"","","",.0190674,"","",.0229569,"","","",.0338653,"","",.0229386, "","","",.0316515,"","",.023503)

est_hL <-rev(est_hL)                                       

est_hH <-rev(est_hH)                                       


for (i in 1:length(estL)) {                                            # loop over a counter the length of the estimate vector
  points(estL[i], i, pch = 19, cex = .5,lwd=4)                               # add the points to the plot
  points(estH[i], i, pch = 19, cex = .5,lwd=4)                               # add the points to the plot
#  lines(c(est_lL[i],est_hL[i]) , c(i, i) ,lwd=3,col="blue")        # add the 95% confidence intervals
#   lines(c(est_lH[i],est_hH[i]) , c(i, i) ,lwd=3,col="red")        # add the 95% confidence intervals
 lines(c(est_lL[i],est_lH[i]) , c(i, i) ,lwd=3,col="blue")        # add the 95% confidence intervals
   lines(c(est_hL[i],est_hH[i]) , c(i, i) ,lwd=3,col="red")        # add the 95% confidence intervals
 text(-0.0075, i, var.names[i], xpd = T, cex = .8)                      # add the variable names
}

# add axes and labels
axis(side = 1)                                                                                          # add bottom axis
abline(v = 0, lty = 3, col = "grey",lwd=3)                                                                    # add verticle line
mtext(side = 1, "(Blue Interval median values; Red Intervals 95th percentile values)", line = 3)                                              # label bottom axis
mtext(side = 3, "Substantive Effect of Systemic Instability Variables in Global Sample", line = 1)   # add title
box()                                







